function ngdomSound(sound, options) {
	if (!ngdom.Engine) return;
	this.engine = ngdom.Engine;
	this.autoplay = options && options.autostart;
	this.loop = options && options.loop;
	this.volume = !options || isNaN(options.volume) ? 100 : options.volume;
	this.currentVolume = this.volume;
	this.playInMenu = !options || typeof(options.playInMenu) == 'undefined' || options.playInMenu;
	this.playStatus = this.autoplay;
	if (!this.playInMenu && !this.engine.begun)
		this.autoplay = false;

	if (typeof(sound) == 'object') {
		sound = sound[0];
	}
	
	var sm_options = {
		id: sound,
		url: sound,
		autoLoad: true,
		autoPlay: this.autoplay,
		volume: this.volume
	};
	if (this.loop) sm_options.onfinish = function () { if (!this.paused && !this.loopPaused) this.play(); };
		
	this.sound = soundManager.createSound(sm_options);
	this.sound.loopPaused = false;
}
ngdomSound.prototype.play = function () {
	this.playStatus = true;
	this.currentVolume = this.volume;
	this.sound.setVolume(this.currentVolume);
	if (this.playInMenu || this.engine.begun) {
		this.sound.loopPaused = false;
		this.sound.play();
	}
};
ngdomSound.prototype.stop = function () {
	this.playStatus = false;
	this.sound.loopPaused = true;
	this.sound.pause();
};
ngdomSound.prototype.isPlaying = function () {
	return !(this.sound.playState == 0 || this.sound.paused || this.fading);
};
ngdomSound.prototype.fadeIn = function (duration) {
	if (this.currentVolume == this.volume && this.sound.playState == 1 && !this.sound.paused) return;
	if (typeof(duration) == 'undefined') duration = 1500;
	if (this.fadeTimer) clearInterval(this.fadeTimer);
	if (this.sound.playState == 0 || this.sound.paused) {
		this.sound.setVolume(0);
		this.currentVolume = 0;
		this.sound.play();
	}
	this.fadeStart = $.now();
	var fadeSound = this;
	var startVolume = this.currentVolume;
	this.fadeTimer = setInterval(function () {
		var percent = ($.now() - fadeSound.fadeStart) / duration;
		if (percent > 1) percent = 1;
		fadeSound.currentVolume = startVolume + Math.floor(percent * (fadeSound.volume - startVolume));
		fadeSound.sound.setVolume(fadeSound.currentVolume);
		if (percent == 1) {
			clearInterval(fadeSound.fadeTimer);
			fadeSound.fadeTimer = null;
		}
	}, 13);
};
ngdomSound.prototype.fadeOut = function (duration, reset) {
	if (this.sound.playState == 0 || this.sound.paused || this.currentVolume == 0) return;
	if (typeof(duration) == 'undefined') duration = 1500;
	if (this.fadeTimer) clearInterval(this.fadeTimer);
	this.fading = true;
	this.fadeStart = $.now();
	var fadeSound = this;
	var startVolume = this.currentVolume;
	this.fadeTimer = setInterval(function () {
		var percent = ($.now() - fadeSound.fadeStart) / duration;
		if (percent > 1) percent = 1;
		fadeSound.currentVolume = startVolume - Math.floor(percent * startVolume);
		fadeSound.sound.setVolume(fadeSound.currentVolume);
		if (percent == 1) {
			if (reset) fadeSound.sound.stop(); 
			else fadeSound.sound.pause();
			clearInterval(fadeSound.fadeTimer);
			fadeSound.fadeTimer = null;
			fadeSound.fading = false;
		}
	}, 13);
};